package com.qys.livesMall.system.controller.sys;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qys.livesMall.common.exception.QysException;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.framework.view.BaseQuery;
import com.qys.livesMall.system.enums.SystemMessageEnum;
import com.qys.livesMall.system.model.dto.sys.SysLanguageTextDTO;
import com.qys.livesMall.system.model.vo.sys.SysLanguageTextVO;
import com.qys.livesMall.system.service.SysLanguageTextService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 多语言文本 前端控制器
 * </p>
 *
 * @author 
 * @since 2023-09-25
 */
@RestController
@RequestMapping("/sys/sysLanguageText")
@Tag(name = "多语言文本管理", description = "多语言文本管理")
public class SysLanguageTextController {

    @Resource
    private SysLanguageTextService sysLanguageTextService;

    @Operation(summary = "添加")
    @PostMapping("/add")
    public R add(@RequestBody @Validated SysLanguageTextDTO sysLanguageTextDTO){
        return sysLanguageTextService.add(sysLanguageTextDTO)? R.ok():R.fail();
    }

    @Operation(summary = "修改")
    @PostMapping("/update")
    public R update(@RequestBody @Validated SysLanguageTextDTO sysLanguageTextDTO){
        if (null == sysLanguageTextDTO.getId()){
            throw new QysException(SystemMessageEnum.SYSTEM_NOT_ID);
        }
        return sysLanguageTextService.updateInfo(sysLanguageTextDTO)? R.ok():R.fail();
    }

    @Operation(summary = "删除")
    @DeleteMapping(value = "/delete/{id}")
    public R delete(@PathVariable Long id){
        sysLanguageTextService.removeById(id);
        return R.ok();
    }

    @Operation(summary = "查询信息列表")
    @PostMapping("/query")
    public R<IPage<SysLanguageTextVO>> query(@RequestBody @Validated BaseQuery query){
        return R.ok(sysLanguageTextService.queryPage(query));
    }

    @Operation(summary = "查询详情")
    @GetMapping(value = "/info/{id}")
    public R<SysLanguageTextVO>info(@PathVariable Long id){
        return R.ok(sysLanguageTextService.getInfo(id));
    }

    @GetMapping("/getTypeAll")
    @Operation(
            summary = "查询类型列表",
            parameters = {
                    @Parameter(name = "name", description = "类型名称")
            }
    )
    public R<List<SysLanguageTextVO>> getTypeAll(@RequestParam(value = "name",required = false) String name){
        return R.ok(sysLanguageTextService.getTypeAll(name));
    }
}
